
import { BlogApi } from "./common.js";
console.log('aaaaa');
document.getElementById('blog_create').addEventListener('click',handlerCreate);
async function handlerCreate()
{
//.1获取两个元素的值
const titleElem=document.getElementById('blog_title');
const textElem=document.getElementById('inPutTex');
console.log(titleElem);
console.log(textElem);
if(titleElem&&textElem)
{
    console.log("tow true");
    if(titleElem.value.trim()!=''&&textElem.value.trim()!='')
    {
        console.log("four true");
        const title=titleElem.value;
        const text=textElem.value;
        console.log(title);
        console.log(text);
    
try{
       const response=await BlogApi.createBlog(title,text);
       console.log(response);
       if(response.success)
       {
        alert('发布成功');
        window.location.href='/blog/blog_html/blog_home.html';
       }
       else
       {
        alert('发布失败');
       }
    
    }  catch(error)
    {
        alert('请求异常: ' + error.message);
        console.error('完整错误:', error);
    }
}
else{
    alert("请输入有效内容!")
}
}
}
document.getElementById('out').addEventListener('click',out);
function out()
{
  if(confirm('你确定要退出吗?'))
  {
    AuthManager.clearToken();
    window.location.replace('/');
  }
}